package util;

import java.sql.*;

public class DBUtil {
	private DBUtil(){}
    
	private static String url="jdbc:mysql://localhost:3306/oa?useUnicode=true&charactreEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false";
	private static String user="root";
	private static String password="123456";
	private static String className="com.mysql.cj.jdbc.Driver";
	
	static{
		try{
		Class.forName(className);
		}catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException();
		}
	}
	
	public static Connection getconn(){
		Connection conn;
		try {
			conn = DriverManager.getConnection(url,user,password);
			return conn;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException();
		}	
	}
	public static void close(ResultSet rs,Statement stm,Connection conn){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(stm!=null){
			try {
				stm.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
